﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;

namespace Medicalsystem.Update
{
    public partial class FormZip : Form
    {
        public FormZip()
        {
            InitializeComponent();
        }

        private void btn_files_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fld = new FolderBrowserDialog();
            if (fld.ShowDialog() == DialogResult.OK)
            {
                txtFiles.Text = fld.SelectedPath;
            }
        }

        private void btn_zipfile_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "zip文件(*.zip)|*.zip";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                txtZip.Text = sfd.FileName;
            }
        }

        private void btn_do_Click(object sender, EventArgs e)
        {
            if (txtZip.Text.Trim() == "" || txtFiles.Text.Trim() == "")
            {
                MessageBox.Show("信息不能为空");
                return;
            }
            if (ZipFile(txtFiles.Text, txtZip.Text))
            {
                MessageBox.Show("生成成功");
            }

        }
        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="FileToZip"></param>
        /// <param name="ZipedFile"></param>
        /// <returns></returns>
        public Boolean ZipFile(string FileToZip, string ZipedFile)
        {

            try
            {
                FastZip fastZip = new FastZip();

                bool recurse = true;

                //压缩后的文件名，压缩目录 ，是否递归          

                fastZip.CreateZip(ZipedFile, FileToZip, recurse, "");
                return true;
            }
            catch
            {
                MessageBox.Show("压缩失败");
                return false;
            }

        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
